home *** CD-ROM | disk | FTP | other *** search
- /*•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- /* MyMath.c
- /*
- /* Implementations to hide all the ugliness when using floating point and fixed point
- /* math between MPW C and Think C. Instead of figuring out when to and when
- /* not to include SANE.h and Math.h, and their order, just include MyMath.h.
- /*
- /* This file contains routines that are missing when compiling under Think C
- /* with different compiler options. This file is not needed really for MPW C.
- /* Note asin and atan2 are no longer needed in release 1.1 of the sample code.
- /* They have been left in case you need them for your projects.
- /*
- /* Author: Michael Chen, Human Interface Group / ATG
- /* Copyright © 1991-1993 Apple Computer, Inc. All rights reserved.
- /*
- /* Part of Virtual Sphere Sample Code Release v1.1
- /*•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/
-
- #ifndef __MyMath__
- #include "MyMath.h"
- #endif
-
- #ifndef __FIXMATH__
- #include <FixMath.h>
- #endif
-
- #define kPi 3.14159265358979323846
-
- #ifdef THINK_C
-
- extern void x80tox96(void *x80, void *x96);
- extern void x96tox80(void *x96, void *x80);
-
- /*=================================================================================================
- /* asin for Think C since their SANE did not implement asin
- /*
- /* Code adapted from Think C's Clibraries:Sources:math.c
- /*-------------------------------------------------------------------------------------------------*/
- #if !__option(mc68881)
- pascal Real asin (Real x)
- {
- Real y = fabs(x);
-
- if (y > .5) {
- y = 1 - y;
- y = 2 * y - y * y;
- }
- else
- y = 1 - y * y;
- return(atan(x / sqrt(y)));
- }
- #endif //!__option(mc68881)
-
- /*=================================================================================================
- /* atan2 for Think C since their SANE did not implement atan2
- /*
- /* Code adapted from Think C's Clibraries:Sources:math.c
- /*-------------------------------------------------------------------------------------------------*/
- #if !__option(mc68881)
- pascal Real atan2 (Real y, Real x)
- {
- Real z;
-
- if (x == 0 && y == 0) {
- if (qDebug) ("\p atan2: both arguements are zero");
- return (0);
- }
- z = atan (y / x);
- if (x < 0) {
- if (y < 0)
- z -= kPi;
- else
- z += kPi;
- }
- return(z);
- }
- #endif //!__option(mc68881)
-
-
- /*=================================================================================================
- /* Real2Fix for Think C when using "Generate 68881 instructions"
- /*-------------------------------------------------------------------------------------------------*/
- #if __option(mc68881)
- pascal Fixed Real2Fix (Real a)
- {
- Fixed result;
- extended temp;
-
- x96tox80 (&a, &temp);
- return (X2Fix (temp));
- }
- #endif //__option(mc68881)
-
- /*=================================================================================================
- /* Fix2Real for Think C when using "Generate 68881 instructions"
- /*-------------------------------------------------------------------------------------------------*/
- #if __option(mc68881)
- pascal Real Fix2Real (Fixed a)
- {
- Real result;
- extended temp;
-
- temp = Fix2X (a);
- x80tox96 (&temp, &result);
- return (result);
- }
- #endif //__option(mc68881)
-
-
-
- #endif THINK_C
-
-